/**
 * 
 */
$(document).ready(function(){
	//设置中心点
	var position=new AMap.LngLat(116.397428,39.90923);
	window.mapObj=new AMap.Map("container",{
		view: new AMap.View2D({
			center:position,
			zoom:14,
			rotation:0,
			resizeEnable: true
		}),
		lang:"zh_cn"//设置语言类型，中文简体
	});
	//增加切换地图的控件
	var a = mapObj.plugin(["AMap.MapType"],function(){
	    //地图类型切换
	    var type= new AMap.MapType({
	    defaultType:0 //使用2D地图
	    });
	    mapObj.addControl(type);
	});
	AMap.event.addListener(mapObj, 'change' ,function(e){
		alert();
	});
	AMap.event.addListener(mapObj, 'movestart', function(e) {
		var slng = windObj.header.slng;
		var slat = windObj.header.slat;
		var spixel = mapObj.lnglatTocontainer(new AMap.LngLat(slng, slat));
		var spixelX = spixel.getX();
		var spixelY = spixel.getY();
		
		var elng = windObj.header.elng;
		var elat = windObj.header.elat;
		var epixel = mapObj.lnglatTocontainer(new AMap.LngLat(elng, elat));
		var epixelX = epixel.getX();
		var epixelY = spixel.getY();
		windObj.moveTo(spixelX, spixelY, epixelX, epixelY);
	});
	AMap.event.addListener(mapObj, 'moveend', function(e) {
		var slng = windObj.header.slng;
		var slat = windObj.header.slat;
		var spixel = mapObj.lnglatTocontainer(new AMap.LngLat(slng, slat));
		var spixelX = spixel.getX();
		var spixelY = spixel.getY();
		
		var elng = windObj.header.elng;
		var elat = windObj.header.elat;
		var epixel = mapObj.lnglatTocontainer(new AMap.LngLat(elng, elat));
		var epixelX = epixel.getX();
		var epixelY = spixel.getY();
		windObj.moveTo(spixelX, spixelY, epixelX, epixelY);
	});
	AMap.event.addListener(mapObj, 'dragging', function(e){
		var slng = windObj.header.slng;
		var slat = windObj.header.slat;
		var spixel = mapObj.lnglatTocontainer(new AMap.LngLat(slng, slat));
		var spixelX = spixel.getX();
		var spixelY = spixel.getY();
		
		var elng = windObj.header.elng;
		var elat = windObj.header.elat;
		var epixel = mapObj.lnglatTocontainer(new AMap.LngLat(elng, elat));
		var epixelX = epixel.getX();
		var epixelY = spixel.getY();
		windObj.moveTo(spixelX, spixelY, epixelX, epixelY);
	});
	AMap.event.addListener(mapObj,'zoomchange',function(e){
		var slng = windObj.header.slng;
		var slat = windObj.header.slat;
		var elng = windObj.header.elng;
		var elat = windObj.header.elat;
		
		var spixel = mapObj.lnglatTocontainer(new AMap.LngLat(slng, slat));
		var spixelX = spixel.getX();
		var spixelY = spixel.getY();
		
		var epixel = mapObj.lnglatTocontainer(new AMap.LngLat(elng, elat));
		var epixelX = epixel.getX();
		var epixelY = epixel.getY();
		
		var width = parseInt(epixelX - spixelX);
		var height = parseInt(epixelY - spixelY);
		windObj.zoom(width,height);
		windObj.moveTo(spixelX, spixelY, epixelX, epixelY);
	});

	AMap.event.addListener(mapObj,'zoomend',function(e){
		clearTimeout(windObj.animateTimer);
		windObj.draw();
	});
	//地图加载完成事件
	AMap.event.addListener(mapObj,'complete',function(){
		windObj.initialize();
	});
	/**
	var ll = mapObj.containTolnglat(new AMap.Pixel(100, 100));
	console.log(ll.getLng() + ' >>>>>>>>>> ' + ll.getLat());
	var ll = mapObj.containTolnglat(new AMap.Pixel(872, 539));
	console.log(ll.getLng() + ' >>>>>>>>>> ' + ll.getLat());
	**/
});